package com.gwnet.common.config;

import cn.hutool.core.util.StrUtil;
import com.gwnet.common.bean.WxApp;
import com.gwnet.common.bean.WxMiniApp;
import com.gwnet.common.core.exception.base.BaseException;
import com.gwnet.common.service.SysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author: WangLiang
 * @date: 2024/7/20 9:53
 */
@Component
public class PlatformConfig {


    private final SysConfigService sysConfigService;

    @Autowired
    public PlatformConfig(SysConfigService sysConfigService) {
        this.sysConfigService = sysConfigService;
    }


    public WxApp getWxApp() {
        WxApp wxApp = sysConfigService.getSysConfigObject(Constant.MX_APP_CONFIG, WxApp.class);
        if (wxApp == null || StrUtil.isBlank(wxApp.getAppId())) {
            throw new BaseException("请在后台页面设置微信开放平申请应用相关信息后，再进行操作");
        }
        return wxApp;
    }

    public WxMiniApp getWxMiniApp() {
        WxMiniApp wxMiniApp = sysConfigService.getSysConfigObject(Constant.MA_CONFIG, WxMiniApp.class);
        if (wxMiniApp == null || StrUtil.isBlank(wxMiniApp.getAppId())) {
            throw new BaseException("请在后台页面设置微信小程序信息后，再进行操作");
        }
        return wxMiniApp;
    }

    public WxMiniApp getWxRiderMiniApp() {
        WxMiniApp wxMiniApp = sysConfigService.getSysConfigObject(Constant.MA_RIDER_CONFIG, WxMiniApp.class);
        if (wxMiniApp == null || StrUtil.isBlank(wxMiniApp.getAppId())) {
            throw new BaseException("请在后台页面设置骑手端微信小程序信息后，再进行操作");
        }
        return wxMiniApp;
    }




}
